<?php
namespace App\Constants;
/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2020/10/30
 * Time: 下午3:20
 */

class HttpReturn
{
    const REQEST_OK = '请求成功';
    /**
     * 接口返回的结构
     * @return array
     */
    private static function getReturnConStruct():array
    {
        return [
            'code'  => HttpCode::CODE_OK,
            'msg'   => self::REQEST_OK,
            'data'  => (object)[]
        ];
    }

    /**
     * 成功的
     * @param string $msg
     * @param array $data
     * @return array
     */
    public static function getParseCon(int $type,string $msg, array $inter_data = []):array
    {
        $data = self::getReturnConStruct();
        switch ($type){
            case HttpStatus::OK:
                //OK
                $data['code'] = HttpCode::CODE_OK;
                break;
            case HttpStatus::ERROR:
                //ERROR
                $data['code'] = HttpCode::CODE_BAD_REQUEST;
                break;
        }
        if (!empty($msg)){
            $data['msg'] = $msg;
        }
        if (empty($inter_data)){
            unset($data['data']);
        }else {
            $data['data'] = $inter_data;
        }
        return $data;
    }
}
